package com.ronsicecream.pos.master.status;

import com.buanalintas.bynga.Action;
import com.buanalintas.bynga.Dictionary;
import com.buanalintas.bynga.Field;
import com.buanalintas.bynga.Page;
import com.ronsicecream.pos.entities.PosMasterStatus;
import javax.persistence.EntityManager;
import javax.persistence.Query;

public class Status extends Page {

    private Field statusId;
    private Field statusName;

    public Status() {
        setTheClass(PosMasterStatus.class);

        statusId = new Field();
        statusId.setName("statusId");
        statusId.setCaption("id");
        statusId.setListProperties(" align=\"right\" width=\"5%\" nowrap");
        statusId.setInputProperties(" status=\"20\"");
        getFields().add(statusId);

        statusName = new Field();
        statusName.setName("statusName");
        statusName.setCaption("status");
        statusName.setListProperties(" align=\"left\" width=\"95%\" nowrap");
        statusName.setInputProperties(" status=\"30\"");
        statusName.setRequired(true);
        getFields().add(statusName);
        
        fillFields();

        getFieldsUnique().add(new Field[]{statusName});
        getFieldsAdd().remove(statusId);
        getFieldsEdit().remove(statusId);
        getFieldsList().remove(statusId);

        setExportList(getClass().getResourceAsStream("StatusList.jasper"));
        setExport(getClass().getResourceAsStream("Status.jasper"));
        getController().setOrder(statusId);

        getActions().remove(Action.ADD);
        getActions().remove(Action.DELETE);
        getActions().remove(Action.DELETE_MULTI);
        getActions().remove(Action.EDIT);
    }

    public static PosMasterStatus getStatusGood(EntityManager em) {
        try {
            Query query = em.createQuery("SELECT t FROM PosMasterStatus t WHERE t.statusId=1");
            return (PosMasterStatus) query.getSingleResult();
        } catch (Exception e) {
        }
        return null;
    }

//    public static PosMasterStatus getStatusDamaged(EntityManager em) {
//        try {
//            Query query = em.createQuery("SELECT t FROM PosMasterStatus t WHERE t.statusId=2");
//            return (PosMasterStatus) query.getSingleResult();
//        } catch (Exception e) {
//        }
//        return null;
//    }
//
//    public static PosMasterStatus getStatusSale(EntityManager em) {
//        try {
//            Query query = em.createQuery("SELECT t FROM PosMasterStatus t WHERE t.statusId=3");
//            return (PosMasterStatus) query.getSingleResult();
//        } catch (Exception e) {
//        }
//        return null;
//    }

    @Override
    public void beforeView() {
        beforeList();
    }

    @Override
    public void beforeExport() {
        getExportParams().put("title", Dictionary.getValue(this, "Status"));
    }

    @Override
    public void beforeExportMulti() {
        beforeExport();

    }
}
